package com.leyou.gateway.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * @ClassName : RateLimitConfig  //类名
 * @Description : KeyResolver的Bean实例  //描述
 * @Author : qingfeng  //作者
 * @Date: 2020-09-14 11:23  //时间
 */
@Configuration
public class RateLimitConfig {
    //定义一个KeyResolver
    @Bean
    public KeyResolver ipKeyResolver() {
        // JDK8 的Lambda写法：
        return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
//        return new KeyResolver() {
//            @Override
//            public Mono<String> resolve(ServerWebExchange exchange) {
//                return Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
//            }
//        };

    }
}
